import matplotlib.pyplot as plt
import numpy as np
import pymysql

db = pymysql.connect(
    host="172.17.9.105",
    user="cs_platform",
    password="cs_platfm_01",
    database="icrg_test",
)

c = db.cursor()
sql = "select crawl_date  as s,avg(price) as a from h_p group by crawl_date order by crawl_date "
c.execute(sql)
res = c.fetchall()
x_arr = []
y_arr = []
for r in res:
    x_arr.append(r[0])
    y_arr.append(r[1])
c.close()
db.close()
x = np.array(x_arr)
y = np.array(y_arr)

plt.title("house price statistics")
plt.bar(x, y)
plt.show()
